<?PHP

// This is the default site address.

$gblPageAddr = "http://www.eparinay.com/";

//$gblPageAddr = "http://www.purabdayanand.com/";

ini_set("session.gc_maxlifetime","1800");



$file_upload_path = "";

// This is the default email address of admin to send email from the system.

$gblAdminEmail = "support@eparinay.com";

$gbl_request_email = "support@eparinay.com";

$pagecount=15;

$pagecount_1=10;

// This is a list of ids for the static pages of front end.

$page_about_us = 1;

$page_advertise_with_us = 2;

$page_contact_us = 3;

$page_terms_and_conditions = 4;

$page_privacy_policy = 5;

$page_disclaimer = 6;

$page_customer_support=7;


function chk_session()

{

	//ob_start();

	session_start();

	require_once("dbconnect.php");



	if(!isset($_SESSION['gbl_username']) || !isset($_SESSION['gbl_user_id']))

	{

		header("location:index.html");

	}

}



function chk_cust_session()

{

	//ob_start();

	session_start();



	if(!isset($_SESSION['gbl_cust_username']) || !isset($_SESSION['ep_customer_id']))

	{

		header("location:login.php");

	}

}



function chk_session_admin()

{

	if($_SESSION['gbl_user_type'] != 'A')

	{

		header("location:index.html");

	}

}



function alphasearch($filename,$currentstr,$linkclass,$txtclass)

{

	foreach(range('A','Z') as $val)

	{

		if ($currentstr==$val) echo "<span class='$txtclass'>$val</span>\n";

		else echo "<a href='$filename?str=$val' class='$linkclass'>$val</a>\n";

		echo "&nbsp;&nbsp;";

	}

}



function createRandomPassword() {

	$chars = "abcdefghijkmnopqrstuvwxyz023456789";

	srand((double)microtime()*1000000);

	$i = 0;

	$pass = '' ;

	while ($i <= 7) {

	$num = rand() % 33;

	$tmp = substr($chars, $num, 1);

	$pass = $pass . $tmp;

	$i++;

	}

	return $pass;

}



function displayPageNo($b,$tot,$qrystr,$class,$cnt)

{

	print "<center><table><tr><td align=center class='form-txt'><span class=\"justify-txt-11\">Page : &nbsp;<span>";

	$i=0;

	while ($i<$tot/$cnt)

	{

	 	$c=$i+1;

		if ($i==$b/$cnt)

		{

			echo "<span class=\"nav_ddnum\">$c&nbsp;&nbsp;<span>";

		}

		else

		{

			$b2=$i*$cnt;

			if ($qrystr!="")

			{

				$q="&$qrystr";

			}

			echo "<a href=\"$PHP_SELF?1=1$q&b=$b2\" class='dddd'>$c</a>&nbsp;&nbsp;";

			if($i%19==0) echo "<BR>";

		}

		$i+=1;

	}

	print "</td></tr></table></center>";

}



function displayPageNoCertify($b_u,$tot_u,$qrystr_u,$class_u,$cnt_u)

{

	print "<center><table><tr><td align=center class='form-txt'><span class=\"justify-txt-11\">Page : &nbsp;<span>";

	$i=0;

	while ($i<$tot_u/$cnt_u)

	{

	 	$c=$i+1;

		if ($i==$b_u/$cnt_u)

		{

			echo "<span class=\"pagination\">$c&nbsp;&nbsp;<span>";

		}

		else

		{

			$b2_u=$i*$cnt_u;

			if ($qrystr_u!="")

			{

				$q_u="&$qrystr_u";

			}

			echo "<a href=\"$PHP_SELF?2=2$q_u&b_u=$b2_u\" class='link-pagination'>$c</a>&nbsp;&nbsp;";

			if($i%19==0) echo "<BR>";

		}

		$i+=1;

	}

	print "</td></tr></table></center>";

}



function validate_ip($ip){

   $return = TRUE;

   $tmp = explode(".", $ip);

   if(count($tmp) < 4){

      $return = FALSE;

   } else {

      foreach($tmp AS $sub){

         if($return != FALSE){

            if(!eregi("^([0-9])", $sub)){

               $return = FALSE;

            } else {

               $return = TRUE;

            }

         }

      }

   }

   return $return;

}





// Saved search email alerts - Begin Code

function send_saved_searches_emails($listing_code)

{

	global $gblAdminEmail;



	$rsea = mysql_query("select customers.email, saved_search.ssname, saved_search.ssquery1, saved_search.ssquery2 from customers, saved_search where customers.customer_id = saved_search.customer_id and customers.status <> 'D' and saved_search.emailalert = 'Y' and saved_search.deleted = 'N'") or die(mysql_error());



	$subject = "Email alert from www.rentbazaar.com";



	$header = "From: $gblAdminEmail\r\n";

	$header .= "MIME-Version: 1.0\r\n";

	$header .= "Content-type: text/html; charset=iso-8859-1\r\n";





	while ($row = mysql_fetch_array($rsea,MYSQL_ASSOC))

	{

		$emailflag = false;

		$rstemp = mysql_query(preg_replace("/(.*?)group(.*?)/i","$1 and od.listing_code = '$listing_code' GROUP $2",$row["ssquery1"])) or die(mysql_error());

		$tmpcount = mysql_fetch_row($rstemp);

		mysql_free_result($rstemp);

		if ($tmpcount[0] != 0) $emailflag = true;

		if (strlen($row["ssquery2"]) > 2)

		{

			$rstemp = mysql_query(preg_replace("/(.*?)group(.*?)/i","$1 and od.listing_code = '$listing_code' GROUP $2",$row["ssquery2"])) or die(mysql_error());

			$tmpcount = mysql_fetch_row($rstemp);

			mysql_free_result($rstemp);

			if ($tmpcount[0] != 0) $emailflag = true;

		}

		if ($emailflag)

		{

			$body = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><style>.orange-table{    border-style: solid;	border-width: 1px;	border-color: #FF5200;	border-collapse: collapse}.form-txt{font-size: 13px;COLOR: #1D1DA2;font-weight: bold;font-family: arial, verdana}.normal-txt{    font-size: 12px;    COLOR: #414141;    font-family: arial, verdana}</style></head>

					<body leftmargin=\"0\" topmargin=\"10\" marginheight=\"0\" marginwidth=\"0\">

					<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" align=\"center\" class=\"orange-table\" width=\"90%\">

					<tr><td class=\"form-txt\">Dear Customer,</td></tr>

					<tr><td class=\"normal-txt\">A new listing with listing code : <strong>".$listing_code."</strong> has been added to the RentBazaar website that matches your saved search criteria - <strong>".$row["ssname"]."</strong><br></td></tr><tr><td class=\"form-txt\">Regards,<br>The RentBazaar Team.</td></tr></table></body></html>";



			//echo $row["email"]." - ".$listing_code." - ".$row["ssname"]."<br>";

			mail_new($row["email"],$subject,$body,$header,$gblAdminEmail,"");

			// send email to customer to email id $row["customers.email"] and listing code = $listing_code ... name of saved search $row["saved_search.ssname"]

		}

	}

	mysql_free_result($rsea);

}

// Saved search email alerts - End Code



function validate_listing_code($ls_code)

{

	$sql = "select listing_id, listing_type from order_details where status='A' AND listing_code ='".$ls_code."' AND date_expired > now()";

	$rw = mysql_query($sql);

	if($row=mysql_fetch_array($rw)){



	switch ($row['listing_type']) {

		case 'Residential':

			$f_addr="residential";

			$tbl="listing_residential";

			$col="residential_listing_id";

			$var_details_page = "search_details_residential.php";

			break;

		case 'Ceremonial':

			$f_addr="ceremonial";

			$tbl="listing_ceremonial";

			$col="ceremonial_listing_id";

			$var_details_page = "search_details_ceremonial.php";

			break;

		case 'Commodities':

			$f_addr="commodities";

			$tbl="listing_commodities";

			$col="commodities_listing_id";

			$var_details_page = "search_details_commodities.php";

			break;

		case 'Microsite':

			$f_addr="microsite";

			$tbl="listing_microsite";

			$col="microsite_listing_id";

			$var_details_page = "search_details_microsite.php";

			break;

		case 'Office':

			$f_addr="office";

			$tbl="listing_office";

			$col="office_listing_id";

			$var_details_page = "search_details_office.php";

			break;

		case 'Retail':

			$f_addr="retail";

			$tbl="listing_retail";

			$col="retail_listing_id";

			$var_details_page = "search_details_retail.php";

			break;

		case 'Roommates':

			$f_addr="roommates";

			$tbl="listing_roommates";

			$col="roommates_listing_id";

			$var_details_page = "search_details_roommates.php";

			break;

		case 'Services':

			$f_addr="services";

			$tbl="listing_services";

			$col="services_listing_id";

			$var_details_page = "search_details_services.php";

			break;

		case 'Shortstay':

			$f_addr="shortstay";

			$tbl="listing_shortstay";

			$col="shortstay_listing_id";

			$var_details_page = "search_details_shortstay.php";

			break;

		case 'Storage':

			$f_addr="storage";

			$tbl="listing_storage";

			$col="storage_listing_id";

			$var_details_page = "search_details_storage.php";

			break;

		case 'Vehicle':

			$f_addr="vehicle";

			$tbl="listing_vehicle";

			$col="vehicle_listing_id";

			$var_details_page = "search_details_vehicle.php";

			break;

		}



		$sql_status="select r.$col, r.title, c.city from $tbl as r, cb_city as c where r.city = c.city_id AND r.$col=".$row['listing_id'];

		$rw_status=mysql_query($sql_status);

		if($row_status=mysql_fetch_array($rw_status))

		{

			$tmp_str = "<tr>

							<td class=\"homepage-headers\">

								<table width=\"98%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\">

									<tr>

										<td class=\"homepage-headers\" width=\"50%\">".substr(stripslashes($row_status[1]), 0, 27)."..</td>

										<td class=\"homepage-headers\" width=\"25%\">$row_status[2]</td>

										<td width=\"25%\"><a href=\"$var_details_page?lid=$row_status[0]\" class=\"link-inactive\" target=\"_blank\">View Details</a></td>

									</tr>

								</table>

							</td>

						</tr>

						<tr>

							<td height=\"2\"></td>

						</tr>";

		}

	}

	return $tmp_str;

}

?>